package com.alibaba.csp.nacos;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;


@Configuration
public class ConfigPublisher {

    private String dataId="fules";

    private String group="sentinelGroup";

    @Autowired
    private NacosConfigManager nacosConfigManager;




    public void publishRules(String jsonString){
        String fileExtension = nacosConfigManager.getNacosConfigProperties().getFileExtension();
        try {
            nacosConfigManager.getConfigService().publishConfig(dataId, group,jsonString,fileExtension);
        } catch (NacosException e) {
            e.printStackTrace();
        }

    }

    public String getDataId() {
        return dataId;
    }

    public void setDataId(String dataId) {
        this.dataId = dataId;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }
}
